package com.alan.api.config;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

/**
 * 使用 fastjson 解析数据
 * url: http://www.jianshu.com/p/45682cd30ca2
 * Created by Alan on 17-12-12
 */
public class FastJsonHttpMessageConverterEx extends FastJsonHttpMessageConverter {

    public FastJsonHttpMessageConverterEx() {
        // 在这里配置 fastjson 特性
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        // 自定义时间格式
        fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
        // 正常转换 null 值
        fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue);
        this.setFastJsonConfig(fastJsonConfig);
    }

    @Override
    protected boolean supports(Class<?> clazz) {
        return super.supports(clazz);
    }

}
